package com.jmm.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jmm.api.dao.DemoDao;
import com.jmm.api.pojo.domain.DemoDO;
import com.jmm.api.pojo.dto.base.QueryPage;
import com.jmm.api.service.DemoService;
import com.jmm.common.utils.PageUtils;
import com.jmm.common.utils.QueryPageUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 这是一个分页的demo
 *
 * @oauth Yeohwah
 * @createDate 2019/3/6 0006
 * @info
 */
@Service("demoService")
public class DemoServiceImpl extends ServiceImpl<DemoDao, DemoDO> implements DemoService {
    /**
     * 包装对象传入
     * page: {pageNo pageSize}
     * @param queryPage
     * @return
     */
    @Override
    public PageUtils queryPage(QueryPage queryPage) {
        IPage<DemoDO> page = this.baseMapper.selectPage(
                new QueryPageUtils<DemoDO>(queryPage).getPage(),
                new QueryWrapper<DemoDO>().lambda()
                        .orderByAsc(DemoDO::getId)
        );
        return new PageUtils(page);
    }

    /**
     * 普通参数传入
     * pageNo pageSize
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<DemoDO> page = this.baseMapper.selectPage(
                new QueryPageUtils<DemoDO>(params).getPage(),
                new QueryWrapper<DemoDO>().lambda()
                        .orderByAsc(DemoDO::getId)
        );
        return new PageUtils(page);
    }
}
